{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gurobipy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "m = Model(\"lp1\")\n",
    "\n",
    "# create variables\n",
    "x = m.addVar(vtype=GRB.CONTINUOUS, name=\"x\")\n",
    "y = m.addVar(vtype=GRB.CONTINUOUS, name=\"y\")\n",
    "z = m.addVar(vtype=GRB.CONTINUOUS, name=\"z\")\n",
    "w = m.addVar(vtype=GRB.CONTINUOUS, name=\"w\")\n",
    "\n",
    "m.setObjective(3*x+9*y+20*z+19*w, GRB.MINIMIZE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<gurobi.Constr *Awaiting Model Update*>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# add constraints\n",
    "m.addConstr(110*x + 160*y + 420*z + 260*w >=2000, \"c0\")\n",
    "m.addConstr(4*x + 8*y + 4*z + 14*w >=55, \"c1\")\n",
    "m.addConstr(2*x + 285*y + 22*z + 80*w >=800, \"c2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimize a model with 3 rows, 4 columns and 12 nonzeros\n",
      "Coefficient statistics:\n",
      "  Matrix range     [2e+00, 4e+02]\n",
      "  Objective range  [3e+00, 2e+01]\n",
      "  Bounds range     [0e+00, 0e+00]\n",
      "  RHS range        [6e+01, 2e+03]\n",
      "Presolve removed 0 rows and 1 columns\n",
      "Presolve time: 0.01s\n",
      "Presolved: 3 rows, 3 columns, 9 nonzeros\n",
      "\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "       0    0.0000000e+00   2.850000e+02   0.000000e+00      0s\n",
      "       2    6.7096358e+01   0.000000e+00   0.000000e+00      0s\n",
      "\n",
      "Solved in 2 iterations and 0.01 seconds\n",
      "Optimal objective  6.709635836e+01\n"
     ]
    }
   ],
   "source": [
    "m.optimize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x 14.244279729294231\n",
      "y 2.7070576861102156\n",
      "z 0.0\n",
      "w 0.0\n"
     ]
    }
   ],
   "source": [
    "for v in m.getVars():\n",
    "    print(v.varName, v.x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
